package org.grow.present.controller.auth;


import org.grow.present.entity.Menu;
import org.grow.present.entity.UserInfo;
import org.grow.present.interceptor.AuthInterceptor;
import org.grow.present.mapper.MenuMapper;
import org.grow.present.mapper.UserInfoMapper;
import org.grow.present.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: xwg
 * @CreateDate: 2023/9/22
 */

@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private MenuMapper menuMapper;

    @GetMapping("/findAll")
    public List<Menu> findAll() {
        return menuMapper.selectList(null);
    }

    @Autowired
    private UserInfoMapper userInfoMapper;

    @GetMapping("/findByUID")
    public List<Menu> findByUID() {
        String UID = AuthInterceptor.getUID();
        UserInfo userInfo = userInfoMapper.findById(UID);
        String menus = userInfo.getMenus();
        String[] menuArray = (menus.split(","));
        return menuMapper.findInMenuIds(menuArray);
    }

}
